// pages/adviser/adviser.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    isDuaration: true,
    ask_state: null,
    ask_id: null,
    adviserList: null
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    setTimeout(() => {
      this.setData({
        isDuaration: false,
        
      })
    },1000)
    console.log(options,9)
    this.setData({
      ask_state: options.detail,
      ask_id: options.id
    })
    var flag = options.flag;
    let ask_id = this.data.ask_id
    // app.core('get', 'getAdviserByNewhouseProjectId?projectId=' + ask_id +'','',(res) => {
    //   console.log(res.data)
    //   this.setData({
    //     adviserList: res.data
    //   })
    // })

    let siteId = app.globalData.cityCode
    var projectId = this.data.id;
    console.log(siteId)
    app.core('get', 'getAgentAndAdviser', { siteId: siteId, projectId: ask_id }, (res) => {
      console.log(res)
      if (res.resultCode === 200) {
        if(flag == 1){
          this.setData({
            adviserList: res.data.adviserList
          })
        }else{
          this.setData({
            agentList: res.data.agentList,
          })
        }
       
      }
    })


  },

  //置业顾问 拨打电话
  phone_now: function (e) {
    // console.log(e.currentTarget.dataset)
    let phone = e.currentTarget.dataset.phone
    console.log(phone)
    wx.makePhoneCall({
      phoneNumber: phone
    })
  },

   // 经纪人 复制微信
  copywx(e) {
    console.log(e.target.dataset.id)
    let id = e.target.dataset.id
    let agentList = this.data.agentList
    let wxchat = agentList[id].wechatId
    console.log(wxchat)
    wx.setClipboardData({
      //准备复制的数据
      data: wxchat,
      success: function (res) {
        wx.showToast({
          title: '复制成功，添加经纪人后获取更多置业消息',
          icon: 'none',
          duration: 1000
        })
      }
    });
  },
  //经纪人 拨号
  dial(e) {
    console.log(e.target.dataset.phone)
    var mobile = e.target.dataset.phone
    wx.showModal({
      title: '系统提示',
      content: '确定要联系 ' + mobile + ' 号码吗',
      success(res) {
        if (res.confirm) {
          wx.makePhoneCall({
            phoneNumber: mobile
          })
        } else if (res.cancel) {
          console.log('用户点击取消')
        }
      }
    })
  }, 

  // 咨询
  // ask_now() {
  //   let adviser_id = this.data.adviserList[0].id
  //   console.log(adviser_id)
  //   wx.navigateTo({
  //     url: `/pages/adviser/chat/chat?ask_id=${adviser_id}`,
  //   })
  // },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})